package com.linwen.excise.leetcode;

/**
 * @ClassName _867转置矩阵
 * @Description TODO
 * @Author zero
 * @DATE 2024/9/22 3:04 AM
 * @Version 1.0
 */
public class _867转置矩阵 {
    public static void main(String[] args) {
        _867转置矩阵 inst = new _867转置矩阵();
        int[][] arr = new int[][]{{1,2,3},{4,5,6},{7,8,9}};
        inst.transpose(arr);
    }

    public int[][] transpose(int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;
        int[][] res = new int[n][m];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                res[j][i] = matrix[i][j];
            }
        }
        return res;
    }
}
